package com.qutan.app.core.domain;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.qutan.app.core.utils.AppUtils;
import org.hibernate.cfg.ImprovedNamingStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import javax.persistence.*;
import java.util.Date;

/**
 *Created by pwy on 16/5/15
 *
 * 自动递增的工具
 *
 */
@MappedSuperclass
@JsonInclude(JsonInclude.Include.NON_NULL)//如果为空的属性，去除
@JsonIgnoreProperties(value = {"updatedAt", "isDelete"})

public class IDEntity {

    @Id
    /*@TableGenerator(name ="pk_gen",initialValue=100000,allocationSize=100,table="tb_generator",
            pkColumnName="gen_name",
            valueColumnName="gen_value",
            pkColumnValue="CUSTOMER_PK")*/
    @GeneratedValue(strategy = GenerationType.AUTO)
    protected Long id;
    @Column(columnDefinition = " timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP")
    protected Date createdAt = new Date();
    @Column(columnDefinition = " timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
    protected Date updatedAt = new Date();

   /* @Column(columnDefinition = "varchar (20) comment '是否逻辑删除 (是:YES,否:NO)'")
    @Enumerated(EnumType.STRING)
    protected Whether isDelete = Whether.NO;*/

    /*public static final String CHECK_BODY_IS_NOT_NULL = "body 不能为空";
    public static final String CHECK_IDENTIFIER_IS_NOT_NULL = "identifier(唯一标识) 不能为空";
    public static final String REMIND_RECODE_IS_NOT_EXIST = "记录不存在";*/

    public IDEntity() {
    }

    public IDEntity(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Date getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

  /*  public Whether getIsDelete() {
        return isDelete;
    }

    public void setIsDelete(Whether isDelete) {
        this.isDelete = isDelete;
    }*/

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        IDEntity idEntity = (IDEntity) o;

        return id.equals(idEntity.id);

    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }



    //获得redis 存储的key
    @JSONField(serialize = false)
    public static String getRedisStoreKey(Class cls){
        String key= AppUtils.getClassName(cls)+"_set";
        return  key;
    }




}
